package com.xcity.db.entity;

import java.util.Date;

import com.xcity.game.financial.FinancialTemplate;

import naga.x.App;
import naga.x.game.template.TemplateService;

public class Financial {

	private int id; // 自增id
	private int financialId;
	private int phase;
	private long money;
	private Date time;
	
	private FinancialTemplate template;
	
	public Financial() {}
	
	public Financial(FinancialTemplate template) {
		this.template = template;
		this.financialId = template.getId();
		this.phase = 1;
		this.time = new Date();
	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public int getFinancialId() {
		return financialId;
	}

	public void setFinancialId(int financialId) {
		this.financialId = financialId;
		this.template = App.getApp().getServiceManager().get(TemplateService.class).get(FinancialTemplate.class, financialId);
	}

	public int getPhase() {
		return phase;
	}

	public void setPhase(int phase) {
		this.phase = phase;
	}

	public long getMoney() {
		return money;
	}

	public void setMoney(long money) {
		this.money = money;
	}

	public Date getTime() {
		return time;
	}

	public void setTime(Date time) {
		this.time = time;
	}

	public FinancialTemplate getTemplate() {
		return template;
	}

	public void setTemplate(FinancialTemplate template) {
		this.template = template;
	}
	
	public boolean isOver() {
		return money >= template.getTotal() || money + template.getMin() > template.getTotal();
	}
	
	public void addMoney(long val) {
		money += val;
	}

}
